'''
selenium也能执行JavaScript代码，通过execute_script("JavaScript代码")
JavaScript代码：
    1）操作滚动条
        window.scrollTo(x,y)  x为横向滚动条,y为纵向滚动条
        x,y的最大限定值为窗口宽高
        宽：document.body.scrollWidth
        高：document.body.scrollHeight


    2）修改属性
        设置隐藏
        style="display:none"  display: block inline none
        style="visibility:hidden"  visible
    修改属性的JavaScript代码：
       arguments[0].setAttribute("style","display:none")
'''
import time

from  selenium import webdriver


# 获取驱动
driver = webdriver.Edge()
# 通过驱动打开网页
driver.get("http://www.baidu.com")
time.sleep(1)

# 修改窗口大小
driver.set_window_size(800,400)
driver.execute_script("window.scrollTo(0,0)")
time.sleep(1)
# 往右滑
driver.execute_script("window.scrollTo(200,0)")
time.sleep(2)
# 往下滑动
driver.execute_script("window.scrollTo(200,200)")
time.sleep(2)
# 滑倒极限值
driver.execute_script("window.scrollTo(document.body.scrollWidth,document.body.scrollHeight)")
time.sleep(2)

# 网页最大化
driver.maximize_window()
time.sleep(1)

# 修改属性
e= driver.find_element("id","chat-submit-button");
try:
    driver.execute_script('arguments[0].setAttribute("style","visibility: hidden")',e)
    e.click()
except Exception as e1:
    print("执行JavaScript代码表出错了",e1)
time.sleep(2)
driver.execute_script('arguments[0].removeAttribute("style","visibility: hidden")', e)


time.sleep(10)

